<?php
	/**
	* 文章列表
	*/
?>
<script src="<?php echo base_url().$this->config->item('public'); ?>assets/js/edit.js"></script>

	 <div class="navbar navbar-inverse navbar-fixed-top bs-docs-nav">
	  <ul class="breadcrumb">
        <li><a href="#">article</a> <span class="divider">></span></li>
        <li class="active">list</li>
      </ul>
	  </div>
	<!--list table-->
	<table cellspacing="0" class="table table-bordered table-hover table-striped">
        <thead>
		<tr><th colspan="7">
          <ul class="toolbar pull-left">
            <li><label class="checkbox"><input type="checkbox" id='checkAllBox' onclick="checkAll(this,'checkbox_article')">全选</label></li>
            <li><button class="button button-danger"  onclick="del('checkbox_article')"><i class="icon-white icon-trash"></i>批量删除</button></li>
            <li><button class="button button-success" onclick="status('checkbox_article',1)"><i class="icon-white icon-ok"></i>启用</button></li>
            <li><button class="button button-inverse" onclick="status('checkbox_article',0)"><i class="icon-white icon-ban-circle"></i>禁用</button></li>
			<li><a href='/<?php echo $this->config->item('index_page');?>/article/add'><button class="button button-success"><i class="icon-white icon-plus"></i>添加</button></a></li>
          </ul>
		
          </th></tr>
          <tr>
			<th>选择</th>
            <th>序号</th>
            <th>标题</th>
            <th>分类</th>
			<th>发布时间</th>
			<th>状态</th>
            <th>基本操作</th>
          </tr>
        </thead>
        <tbody>
		 <?php
			if($articles){

            /*news列表*/
		
            foreach($articles as $item){
           ?>
            <tr class="list-article">
            <td><input type="checkbox" name="checkbox_article" value="<?php echo $item['id']?>" /></td>
				<td><?php echo $item['id']?></td>
				<td><?php echo $item['title']?></td>
				<td><?php echo $item['category_id']==""?'默认分类':$item['category_id']?></td>
				<td>2014-3-31 10:13:43</td>
				<td>
				<?php
					switch($item['status']){
						case 0:
				?>
						<a href="javascript:status(<?php echo $item['id']?>,1)"><span class="label label-important" title="点击启用">已禁用</span></a>
				<?php
						
						break;
						case 1:
				?>
						<a href="javascript:status(<?php echo $item['id']?>,0)"><span class="label label-success"  title="点击禁用">已启用</span></a>
				<?php
						break;
					}
				?>
				</td>
				<td><a href="/<?php echo $this->config->item('index_page');?>/article/edit/<?php echo $item['id']?>" title='编辑'><i class="icon icon-edit"></i></a>&nbsp;&nbsp;<a href="#" title='禁用'><i class="icon icon-ban-circle"></i></a>&nbsp;&nbsp;<a href="javascript:del(<?php echo $item['id']?>)" title='删除'><i class="icon icon-remove"></a></td>
		
            </tr>
           <?php
            }
   
			}
		?>
  
			<tr><td  colspan="7">
				<ul class="toolbar pull-left">
				<li><label class="checkbox"><input type="checkbox" id='checkAllBox' onclick="checkAll(this,'checkbox_article')">全选</label></li>
				<li><button class="button button-danger"  onclick="del('checkbox_article')"><i class="icon-white icon-trash"></i>批量删除</button></li>
				<li><button class="button button-success" onclick="status('checkbox_article',1)"><i class="icon-white icon-ok"></i>启用</button></li>
				<li><button class="button button-inverse" onclick="status('checkbox_article',0)"><i class="icon-white icon-ban-circle"></i>禁用</button></li>
				<li><a href='/<?php echo $this->config->item('index_page');?>/article/add'><button class="button button-success"><i class="icon-white icon-plus"></i>添加</button></a></li>
			  </ul>
			</td></tr>
        </tbody>
      </table>
	  <!--list table END-->
	  
	  <!--toobar-->
	  <div>

		
		<div class="pagination pull-right">
		
         <?php 	echo $this->pagination->create_links();?>
    
       </div>
	  
	  </div>
	  <!--toobar END-->


<script>


	/**
	*	更新状态
	*	@id 编号 或 编号对应的对象(用于批量操作)
	*	@status 数值代表相关的status 
	*/
	function status(id,status){
		
		ids = id;
		//非数字则为相关对象
		if(isNaN(id)){
			ids = getCheckVlue(id);
			if(ids == ""){
				message('请选择至少一个项目!','warning');
				return false;
			}
		}
		data = {
			'data':{'id':ids,'status':status},
			'url':'<?php echo site_url('/article/status/');?>',
		}
		
		r = ajaxEdit(data);
		
		switch(r.error){
			case 0:
			window.location.reload();
			break;
			case 1:
			message(r.content,'error');
			break;
		}
		
	}
	
	
	/**
	*	删除文章
	*	@id 编号 或 编号对应的对象(用于批量操作)
	*	@status 数值代表相关的status 
	*/
	function del(id){
	
		ids = id;
		//非数字则为相关对象
		if(isNaN(id)){
			
			ids = getCheckVlue(id);
			if(ids == ""){
				message('请选择至少一个项目!','warning');
				return false;
			}
		}
		data = {
			'data':{'id':ids},
			'url':'<?php echo site_url('/article/delete/');?>'
		}
		
		BUI.Message.Confirm('删除后不可恢复,确定删除这些文章吗:<br>'+ids,function(){
			
			r = ajaxEdit(data);
			switch(r.error){
				case 0:
				window.location.reload();
				break;
				case 1:
				message(r.content,'error');
				break;
			}
		
        },'question');
	
	}
	

</script>